<template>
  <!-- 页眉 -->
  <div class="nav">
    <van-icon name="home-o" @click="toIndex" />
    <van-nav-bar title="网易严选" />
    <van-icon name="search" />
  </div>

  <!-- 有地址展示 -->
  <div v-if="addressList.length"></div>

  <!-- 没有地址时候展示 -->
  <div class="kong" v-else>
    <div class="noList">
      <img src="./kong.png" alt="" />
    </div>
    <p>收货地址在哪里</p>
  </div>

  <!-- 新增按钮 -->
  <van-button icon="plus" class="addAddress" type="warning" size="large" @click="addAddress">新增地址</van-button>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import router from '@/router'
import { reqAddressList } from '@/api/address'

// 地址列表
const addressList = ref([])

// 点击home回首页
const toIndex = () => {
  router.push('/')
}

// 点击新增地址
const addAddress = () => {
  // 跳转新增页面
}

// 获取列表方法
const getAddressList = async () => {
  try {
    const res = await reqAddressList()

    addressList.value = res.data as []
  } catch (error) {
    // console.log('无数据')
  }
}

onMounted(() => {
  // 获取订单列表
  getAddressList()
})

// watch()
</script>

<script lang="ts">
export default {
  name: 'VAddress'
}
</script>

<style lang="scss" scoped>
.kong {
  height: 600px;
  overflow: hidden;
  text-align: center;
  font-size: medium;
  .noList {
    margin: 50px auto;
    width: 200px;
    height: 200px;
    img {
      height: 200px;
      widows: 200px;
    }
  }
}
.nav {
  display: flex;
  justify-content: space-between;
  .van-nav-bar {
    width: 200px;
  }
  .van-icon {
    padding: 15px;
  }
}
.logo {
  width: 400px;
  display: flex;
  justify-content: center;
  margin-top: 150px;
}

.addAddress {
  position: relative;
  bottom: 170px;
}
</style>
